package com.lmscn.lms;

import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.wall.WallFilter;
import com.jfinal.config.*;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.druid.DruidPlugin;
import com.lmscn.lms.api.controller.*;
import com.lmscn.lms.api.interceptor.ExceptionAndLogInterceptor;
import com.lmscn.lms.api.model.*;
import com.lmscn.lms.api.util.CommonUtil;
import com.lmscn.lms.commons.GlobalConst;
import com.lmscn.lms.qsws.controller.TransferController;

/**
 * Created by Czl on 2015/7/21.
 */
public class DemoConfig extends JFinalConfig {

	public void configConstant(Constants me) {
		// 加载少量必要配置，随后可用getProperty(...)获取值
		loadPropertyFile("main/resources/a_little_config.txt");
		CommonUtil.mediaUrl = getProperty("mediaUrl");
		CommonUtil.imgUrl = getProperty("imgUrl");
		CommonUtil.uploadShareUrl = getProperty("uploadShareUrl");
		CommonUtil.shareUrl = getProperty("shareUrl");
		CommonUtil.bannerUrl = getProperty("bannerUrl");
		CommonUtil.testInfo = getProperty("testInfo");
		CommonUtil.examInfo = getProperty("examInfo");
		CommonUtil.appKey = getProperty("jpushAppKey");
		CommonUtil.appSecret = getProperty("jpushMasterSecret");
		me.setDevMode(true);
	}

	public void configRoute(Routes me) {
		me.add("/", IndexController.class);
		me.add("/qsws", TransferController.class);
		me.add("/api/user", LoginController.class);
		me.add("/api/course", CourseBaseController.class);
		me.add("/api/courseTopic", CourseTopicController.class);
		me.add("/api/courseStudent", CourseStudentController.class);
		me.add("/api/courseCount", CourseCountController.class);
		me.add("/api/clazz", ClazzController.class);
		me.add("/api/course/exam", CourseExamController.class);
		me.add("/api/submitAnswer", SubmitAnswerController.class);
		me.add("/api/question", QuestionController.class);
		me.add("/api/myExam", MyExamController.class);
		me.add("/api/msgCenter", MsgCenterController.class);
		me.add("/api/feedBack", FeedBackController.class);
		me.add("/api/count", CountController.class);
		me.add("/api/paperResult", TestPaperController.class);
		me.add("/api/aticle", ActicleController.class);
		me.add("/api/teacher", TeacherController.class);
		
		me.add("/api/userStudy", UserStudyController.class);
		
		// me.add("/api/jpush", JpushController.class);
		me.add("/api/sxln", SxlnNewController.class);
	}

	public void configPlugin(Plugins me) {
		DruidPlugin aDruidPlugin = new DruidPlugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password").trim(),
				getProperty("driverClass"));
		aDruidPlugin.start();
//		aDruidPlugin.setInitialSize(50);
		aDruidPlugin.set(10, 50, 100);
		aDruidPlugin.addFilter(new StatFilter());
		WallFilter wall = new WallFilter();
		wall.setDbType("mysql");
		aDruidPlugin.addFilter(wall);
		me.add(aDruidPlugin);
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(aDruidPlugin);
		arp.setDialect(new MysqlDialect());
		me.add(arp);
		arp.addMapping("t_student_count", StudentCount.class); // 映射
		arp.addMapping("t_student", Student.class); // 映射
		arp.addMapping("sys_user", SysUser.class);
		arp.addMapping("sys_properties", SysProperties.class);
		arp.addMapping("t_course_base", CourseBase.class);
		arp.addMapping("t_course_lesson", CourseLesson.class);
		arp.addMapping("t_course_learning_setting", CourseLearningSetting.class);
		arp.addMapping("t_course_category", CourseCategory.class);
		arp.addMapping("t_course_student", CourseStudent.class);
		arp.addMapping("t_course_count", CourseCount.class);
		arp.addMapping("t_course_topic", CourseTopic.class);
		
		arp.addMapping("t_lesson_student_record", LessonStudentRecord.class);
		arp.addMapping("t_clazz", Clazz.class);
		arp.addMapping("t_clazz_student", ClazzStudent.class);
		arp.addMapping("t_clazz_course", ClazzCourse.class);
		arp.addMapping("t_clazz_learning_setting", ClazzLearningSetting.class);
		arp.addMapping("t_org", Org.class);
		arp.addMapping("t_exam", Exam.class);
		arp.addMapping("t_test", Test.class);
		arp.addMapping("t_testpaper", Testpaper.class);
		arp.addMapping("t_testpaper_result", TestpaperResult.class);
		arp.addMapping("t_question", Question.class);
		arp.addMapping("t_question_metas", QuestionMetas.class);
		arp.addMapping("t_question_category", QuestionCategory.class);
		arp.addMapping("t_question_favorite", QuestionFavorite.class);
		arp.addMapping("t_feedback", FeedBack.class);
		arp.addMapping("sys_dict_data", SysDictData.class);
		arp.addMapping("t_teacher", Teacher.class);
		arp.addMapping("t_study_plan", StudyPlan.class);
		arp.addMapping("t_login_count", LoginCount.class);
		arp.addMapping("t_exam_rule", ExamRule.class);
		
		arp.addMapping("t_index_images", BannerImages.class);
		
		// 资讯表 2016年11月11日16:04:44
		arp.addMapping("t_article", Article.class);
		arp.addMapping("t_article_category", ArticleCategory.class);
		arp.addMapping("t_course_category_related", CourseCategoryRelated.class);
		

		/*
		// 推送相关表
		arp.addMapping("t_push", Push.class);
		arp.addMapping("t_push_student", PushStudent.class);
		 
	    // 闪屏页图片表
		arp.addMapping("t_welcome_pages", WelcomPages.class);
		
		// 登录日志表 2017年3月23日14:51:34
		arp.addMapping("t_login_log", LoginLog.class);
		
		// 资讯学员状态表
		arp.addMapping("t_article_student_status", ArticleStudentStatus.class);
		
		// 资讯学员点赞表 
		arp.addMapping("t_article_comment_ckgood", ArticleCommentCkGood.class);
		
		drop table if exists t_course_student_click;
		CREATE TABLE `t_course_student_click`  (
		  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
		  PRIMARY KEY (`id`)
		) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
		
		
		drop table if exists t_tag;
		CREATE TABLE `t_tag` (
		  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
		  PRIMARY KEY (`id`)
		) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
		
		
		drop table if exists t_category_column;
		CREATE TABLE `t_category_column` (
		  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
		  PRIMARY KEY (`id`)
		) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
		
		
		drop table if exists t_push;
		CREATE TABLE `t_push` (
		  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
		  PRIMARY KEY (`id`)
		) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;



		// 标签表
//		arp.addMapping("t_tag", Tag.class);
		// 滚动类别表
//		arp.addMapping("t_category_column", CategoryColum.class);
//		arp.addMapping("t_testpaper_item", TestpaperItem.class);
//		arp.addMapping("t_testpaper_item_result", TestpaperItemResult.class);
//		arp.addMapping("t_question_wrong", QuestionWrong.class);
//		arp.addMapping("t_my_exam", MyExam.class);
//		arp.addMapping("t_student_system_message", SystemMsgStudent.class);
//		arp.addMapping("t_system_message", SystemMessage.class);
//		arp.addMapping("t_my_exam", MyExam.class);
//		arp.addMapping("t_myexam_learning_setting", MyExamLearningSetting.class);
//		arp.addMapping("t_myexam_student", MyExamStudent.class);
//		arp.addMapping("t_online_count", OnlineCount.class);
//		arp.addMapping("t_login_count", LoginCount.class);
//		arp.addMapping("t_index_images", BannerImages.class);
		// 课程分类与课程关联表 2016年12月29日10:14:06 add
		
//		arp.addMapping("t_search_hotkey", SearchHotKey.class);
//		arp.addMapping("t_common_comment", Comment.class);
//		arp.addMapping("t_course_student_status", CourseStudentStatus.class);
//		arp.addMapping("t_course_student_click", CourseStudentClick.class);
//		arp.addMapping("t_course_comment_ckgood", CourseCommentCkGood.class);
//		arp.addMapping("t_course_student_progress", CourseStudentProgress.class);
//		arp.addMapping("t_lesson_student", LessonStudent.class);
//		arp.addMapping("t_search_course_category", SearchCourseCategory.class);
		*
		*/
		
	}

	public void configInterceptor(Interceptors me) {
		GlobalConst.GLOBAL_MAP_CACHE.put("35", new StudyPlan());
		// me.add(new ExceptionAndLogInterceptor());
	}

	public void configHandler(Handlers me) {
		me.add(new ContextPathHandler("ctx"));

	}
}
